package com.woniuxy.shop.dao;

import java.util.ArrayList;
import java.util.List;

import com.woniuxy.shop.entity.CateGory;

/**
*@author 作者：
*version 创建时间：
*类说明：
*/
public class CateGoryDao {
	
	/**
	 * 增加类别
	 * @param cg
	 */
	public void add(CateGory cg) {
		String sql = "insert into shop_category(name, status) values(?,?) ";
		DbHelper.excuteSQL(sql,cg.getName(),cg.getStatus());
	}
	
	
	/**
	 * 修改指定id的类别状态
	 * @param id
	 * @param status
	 */
	public void update(CateGory c) {
		String sql = "update shop_category set status=?,name=? where id=?";
		Object[] obs = {c.getStatus(),c.getName(),c.getId()};
		DbHelper.excuteSQL(sql, obs);
	}
	
	/**
	 * 修改指定id的名称
	 * @param id
	 * @param status
	 */
	public void updateName(int id,String name) {
		String sql = "update shop_category set name=? where id=?";
		DbHelper.excuteSQL(sql, name,id);
	}
	
	
	/**
	 * 删除指定ID的类别信息
	 * @param id
	 */
	public void delete(int id) {
		String sql = "delete from shop_category where id=?";
		DbHelper.excuteSQL(sql, id);
	}
	
	/**
	 * 查询所有的类别信息
	 * @return
	 */
	public List<CateGory> getAllCateGory(){
		List<CateGory> cates = new ArrayList<>();
		String sql = "select * from shop_category";
		cates=DbHelper.executeQuery(sql, CateGory.class);
		return cates;
	}
	
	/**
	 * 根据指定ID查询该类的信息
	 * @param id
	 * @return
	 */
	public CateGory getCateGoryById(int id) {
		String sql = "select * from shop_category where id =?";
		return DbHelper.executeQueryForSingleRow(sql, CateGory.class, id);
	}
	
	/**
	 * 根据指定ID查询该类的信息
	 * @param id
	 * @return
	 */
	public CateGory getCateGoryByName(String name) {
		String sql = "select * from shop_category where name =?";
		return DbHelper.executeQueryForSingleRow(sql, CateGory.class, name);
	}
}
